package com.zmn.brs.drools.bean;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zmn.brs.model.query.rule.EarlyWarningConfig;
import com.zmn.brs.model.vo.rule.objective.ObjectiveRuleVO;
import lombok.*;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 描述： 目标监控
 * @author chongw
 * @since 2021-06-08 14:46
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ObjectiveMonitor implements Serializable {

    private Integer eventCode;

    private Integer subgoalId;

    private Integer objMasterType;

    private Integer objMaster;

    private String objMasterName;

    private Integer deptId;

    private String deptName;

    private Integer subgoalDeptId;

    private Integer ruleId;

    private BigDecimal objectiveValue;

    private BigDecimal realValue;

    private String cubeObjectiveValue;

    private String cubeRealValue;

    private String cubeObjectiveRatioValue;

    private String thresholdValue;

    private Integer droolsId;

    private String droolsName;

    private Boolean result;

    private Integer level;

    private Integer thresholdId;

    private String objName;

    private Integer objCubeId;

    private Double objectiveRatioValue;

    private Integer value1;

    private Integer value2;

    private Integer value3;

    private Integer jobType;

    private Integer sceneId;

    private String taskId;

    private String taskVersionId;

    /**
     * 获取预警值
     * @param level
     * @return
     */
    public static Integer getRule(String thresholdValue, Integer level){
        ObjectiveRuleVO data = JSONObject.parseObject(thresholdValue , ObjectiveRuleVO.class);
        List<EarlyWarningConfig> temp = data.getList().stream().filter(o ->{
            return o.getKey().equals(level);
        }).collect(Collectors.toList());
        EarlyWarningConfig curr = Optional.ofNullable(temp.get(0)).orElse(new EarlyWarningConfig());
        return curr.getValue();
    }

}
